home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / ab20 / hardware / amscsi.lzh / smw.asm < prev   
Assembly Source File  |  1987-05-26  |  4KB  |  179 lines

  1. ;  SMARTWATCH clock driver
  2. ;
  3. ;  R.Frantz 4/3/87
  4. ;
  5. WRTC        equ $808010
  6. RDRTC        equ WRTC+8
  7. Pattern        equ $5CA33AC5
  8. low_time    equ $01234500    ; fake up for rtc
  9. hi_time        equ $87061901    ; my birthday
  10.  
  11.  
  12. _OpenLibrary    EQU    -6*68
  13. _CloseLibrary    EQU    -6*69
  14.  
  15. _Write        EQU    -6*8
  16. _Output        EQU    -6*10
  17. _Execute    EQU    -6*37
  18. ;
  19. ; Call AmigaDOS
  20. ;
  21.     MOVEM   d2/d3,-(sp)
  22.     LEA    DosName(PC),a1    ; Name of the DOS
  23.     MOVEQ    #0,d0        
  24.     MOVEA.L    4,a6        ; Address of EXEC
  25.     JSR    _OpenLibrary(A6)
  26.     MOVEA.L    d0,a5
  27.     TST.L    d0        
  28.     BNE    GetTime        ;OK, read the RTC
  29. ; Something is wrong with the AMIGA , BOMB the system !
  30.     DC.W    $4AFC        
  31. ;
  32. ; Here is the code that is HARDWARE dependant.
  33. ;
  34. GetTime:
  35.     BSR ReadRTC
  36. ;FAKE:     MOVE.L low_time,d2
  37. ;    MOVE.L hi_time,d3
  38.     BSR Decode
  39.  
  40. SetTime:
  41. ;
  42. ; Call AmigaDOS Execute entry
  43.     MOVE.L    #ExecMe,d1
  44.     MOVEQ    #0,d2        ; NIL for Input()
  45.     MOVEQ    #0,d3        ; NIL for Output()
  46.     JSR    _Execute(A5)    ; Call the DOS
  47.     MOVE.L    a5,a1
  48.     JSR    _CloseLibrary(A6)
  49. ; Exit program
  50.     MOVEQ    #0,d0
  51.     MOVEM   (sp)+,d2/d3
  52.     RTS
  53.  
  54. ; Various string constants
  55. Months    DC.B    '-jan-feb-mar-apr-may-jun-jul-aug-sep-oct-nov-dec'
  56. ExecMe    DC.B    'date 00:00:00 00-jst-00',0
  57. DosName    DC.B    'dos.library',0
  58. ;
  59. ; Subroutines
  60. ;
  61.  
  62. Decode:
  63.     MOVE.L     d2,d0        ;get the low data
  64.     ROR.L    #8,d0        ;shitf 1 byte right to get secs.
  65.     MOVE.l    #ExecMe+$C,a0    ;location in ExecMe string
  66.     BSR     ASCII        ;convert to ascii
  67.     ROR.L    #4,d0        ;10 sec
  68.     MOVE.L  #ExecMe+$B,a0
  69.     BSR    ASCII        set 10 sec
  70. ; Next get the min.
  71.     ROR.L    #4,d0        ;min
  72.     move.l     #ExecMe+$9,a0
  73.     BSR    ASCII        ;set min
  74.     ROR.L    #4,d0        ;10 min
  75.     MOVE.L    #ExecMe+$8,a0
  76.     BSR    ASCII        ;set 10 min
  77. ; Get the Hr.
  78.     ROR.L    #4,d0        ;hr
  79.     MOVE.L  #ExecMe+$6,a0
  80.     BSR    ASCII        ;set hr
  81.     ROR.L    #4,d0        ;10 hr
  82.     MOVE.L  #ExecMe+$5,a0    
  83.     BSR    ASCII        ;set 10 hr
  84.     MOVE.L    d3,d0        ;get the high data
  85. ; Get the Date
  86.     ROR.L    #8,d0        ;get the date
  87.     MOVE.L     #ExecMe+$F,a0    
  88.     BSR    ASCII        ;set the date
  89.     ROR.L    #4,d0        ;10 date
  90.     MOVE.L     #ExecMe+$E,a0
  91.     BSR    ASCII        ;set 10 date
  92. ; The month has to be converted into words
  93.     ROR.L     #4,d0        ;get the month
  94.     MOVE.B    d0,d1
  95.     AND.L    #$10,d1        ;check 10s of months
  96.     BNE    AddMonth    ;add 10 to month
  97.     MOVE.B    d0,d1
  98.     BRA    AddMonth1    ;goto 
  99. AddMonth:
  100.     MOVE.L     d0,d1
  101.      ADD.B    #$A,d1        ;add 10 months to the count        
  102. AddMonth1:
  103.     AND.L    #$F,d1        ;mask all upper bits
  104.     SUBQ.L  #1,d1        month now 0-11
  105.     ASL.L    #2,d1        ;multiply by 4
  106.     AND.L    #$3F,d1        ;set a limit
  107.     MOVE.L    d1,a0        
  108.     ADD.L #Months,a0        ;set the offset
  109.     MOVE.L (a0),d1    ;get the name for the month
  110.     MOVE.L #ExecMe+$10,a0    
  111.     MOVE.L d1,(a0)        ;set the month    
  112. ; Now the Year
  113.     ROR.L    #8,d0        ;get year
  114.     MOVE.L    #ExecMe+$16,a0
  115.     BSR    ASCII        ;set yr
  116.     ROR.L     #4,d0        ;get 10s yr
  117.     MOVE.L     #ExecMe+$15,a0
  118.     BSR    ASCII        ;set 10 yr
  119.     RTS            ;done    
  120.  
  121. ASCII:    MOVE.B    d0,d1
  122.     AND.B    #$F,d1        ;mask upper nibble
  123.     OR.B     #$30,d1        ;add $30 for ascii
  124.     MOVE.B    d1,(a0)        ;store in "date" cmd
  125.     RTS            ;done
  126.     
  127.     
  128. ReadRTC:
  129.     MOVE.B  RDRTC,d0    ;Claer Clock
  130.     MOVE.L     #Pattern,d0    ;get the wake up pattern
  131.     BSR     SND32        ;send it
  132.     MOVE.L     #Pattern,d0    ;send it again
  133.     BSR     SND32
  134.     BSR     RD32        ;get the first 4 bytes
  135.     MOVE.L     d0,d2        ;store it
  136.     BSR     RD32        ;get the rest of the data
  137.     MOVE.L     d0,d3        ;store it
  138.     RTS            ;done
  139.  
  140. SetRTC:
  141.     MOVE.B  RDRTC,d0    ;Clear Clock
  142.     MOVE.L     #Pattern,d0    ;get the wake up pattern
  143.     BSR     SND32        ;send it
  144.     MOVE.L     #Pattern,d0    ;send it again
  145.     BSR     SND32
  146.     MOVE.L     d2,d0        ;get the first 4 bytes
  147.     BSR     SND32        ;send it to the clock
  148.     MOVE.L     d3,d0        ;get the rest of the data
  149.     BSR     SND32        ;send it to the clock
  150.     RTS            ;done
  151.  
  152. SND32:    
  153.     MOVE.L     #32,d4    ;load loop counter with 32
  154. S1:
  155.     BTST.L     #0,d0    ;is the bit = zero ?
  156.     BNE     S2    ;send a "one"
  157.     MOVE.B     WRTC,d1    ;send a "zero"
  158. S3:
  159.     ASR.L     #1,d0    ;get the next bit
  160.     SUBQ.L     #1,d4    ;dec the count
  161.     BNE     S1    ;send the next bit
  162.     RTS        ;done
  163. S2:    
  164.     MOVE.B     WRTC+2,d1    
  165.     BRA.S     S3    ;send the next bit
  166.  
  167. RD32:    MOVE.L     #0,d0    ;clr d0
  168.     MOVE.L     #32,d4    ;set the counter to 32
  169. R1:
  170.     MOVE.B     RDRTC,d1    ;get a bit from the smart watch
  171.     AND.L     #1,d1    ;mask all other bits
  172.     OR.L     d1,d0    ;place it in d0
  173.     ROR.L   #1,d0    ;Rotate (d0 -> d31) 
  174.     SUBQ.L     #1,d4    ;dec the counter
  175.     BNE     R1    ;get the next bit
  176.     RTS        ;done
  177.  
  178.     END
  179.